package com.system.borrow.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.system.borrow.R;
import com.system.borrow.bean.TuiJian;

import java.util.ArrayList;
import java.util.List;

/**
 * ================================================
 * 作    者：LuCenly(落尘)
 * 版    本：1.0
 * 创建日期：2016/12/2 14:29
 * 描    述：TODO
 * ================================================
 */
public class LoanAdapter extends BaseAdapter {
    public Context context;
    public LayoutInflater inflater;
    private List<TuiJian> list = new ArrayList<>();
    public LoanAdapter(Context context,List<TuiJian> list) {
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        if(list.size()<2){
            return 1;
        }else if(list.size()%2==0){
            return list.size()/2;
        }else{
            return (list.size()/2)+1;
        }
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if(view==null){
            view = inflater.inflate(R.layout.item_loan,null);
            viewHolder = new ViewHolder();
            viewHolder.iv_img_left = (ImageView) view.findViewById(R.id.iv_img_left);
            viewHolder.tv_name_left = (TextView) view.findViewById(R.id.tv_name_left);
            viewHolder.tv_tag_left = (TextView) view.findViewById(R.id.tv_tag_left);
            view.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) view.getTag();
        }
        return view;
    }
    public class ViewHolder{
        ImageView iv_img_left;
        TextView tv_name_left,tv_tag_left;
    }
}
